package com.ssfeng.youxia.commons;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/***
 * 获取spring的上下文
 */
@Component
public class SpringApplicationContextUtil implements ApplicationContextAware {

	private static ApplicationContext applicationContext;

	private SpringApplicationContextUtil() {}
	
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		SpringApplicationContextUtil.applicationContext = applicationContext;
	}

	public static ApplicationContext getContext() {
		if (applicationContext == null)
			return null;
		return applicationContext;
	}
}
